//InlandWaterAdvModel.h
//Created 01/02/14
//Created By Daniel Bowler
//
//Represents the inland water of a given scene. 

#pragma once

//Inherit from AbstractAdvancedModel
#include "AbstractAdvancedModel.h"

//Effect we use to render the Ocean.
class OceanWaveFX;

//Height scales
#define INLAND_WATER_ADV_MODEL_HEIGHT_SCALE_0 0.6f
#define INLAND_WATER_ADV_MODEL_HEIGHT_SCALE_1 1.4f

class InlandWaterAdvModel : public AbstractAdvancedModel
{
public:
	//Standard constructor/destructor. The init function
	//will be used to init the D3D resources etc. 
	InlandWaterAdvModel();
	~InlandWaterAdvModel();

	//Init the OceanWave. Here we will set the size and location
	void Init(float depth, float width,
		XMFLOAT3 position, ID3D11Device* device);

	//Updates the ocean - In simple terms, animates the waves
	void Update(float delta);

private:
	//Override the Render function - Grahics manager calls this (the friendship
	//is inherited)
	void Render(bool isZPrePass, bool isOpaquePass, bool isShadowPass,		   //Flags telling us what pass it is. 
		VirtualCamera* playerCamera,										   //Player camera - passed from GraphicsInterface
		DirecLightShadowMapData* shadowMap,									   //Single shadow map - passed from GraphicsInterface. 
		SSAOData* ssaoMap,													   //SSAO Map.
		ID3D11ShaderResourceView* envMap,									   //Environment map. 
		ID3D11ShaderResourceView* llb,                                         //Light list buffer - gloabl set of lights. 
		ID3D11ShaderResourceView* llibO, ID3D11ShaderResourceView* llsebO,     //Opaque Tile Based Forward buffers. 
		ID3D11ShaderResourceView* llibT, ID3D11ShaderResourceView* llsebT,     //Transparant pass. 
		DirectionalLight* dLightArr, unsigned dLightCount,					   //Directional lights and light count. 
		XMFLOAT3 &hemiColDown, XMFLOAT3 &hemiColRange,						   //Hemispherical ambient lighting data.
		CXMMATRIX &view, CXMMATRIX &proj,									   //Cameras view/proj or the shadow maps view/proj depending on the pass. 
		ID3D11DeviceContext* context);										   //Context we are rendeirng through. 

private:
	//Effect we use to render the ocean
	OceanWaveFX* effect;

	//Ocean vertex and index buffers. 
	ID3D11Buffer* wavesVB;
	ID3D11Buffer* wavesIB;

	//Normal maps - we actually have two. 
	ID3D11ShaderResourceView* wavesNormalMap0;
	ID3D11ShaderResourceView* wavesNormalMap1;

	//Cube map for the reflection mapping
	ID3D11ShaderResourceView* reflectionMap;
	//Number of indicies to draw
	unsigned wavesNumIndicies;

	//Waves material. 
	Material gridMaterial;

	//Cube map. 
	ID3D11ShaderResourceView* cubeMap;
	//Ocean texture
	ID3D11ShaderResourceView* waveTex;

private:
	//Wave texture transformation data (Updated per frame)
	//and matricies (Uploaded to GPU per frame)
	XMFLOAT2 normalOffset0;
	XMFLOAT2 normalOffset1;
	XMFLOAT2 dispOffset0;
	XMFLOAT2 dispOffset1;
	XMFLOAT4X4 normalOffset0Mat;
	XMFLOAT4X4 normalOffset1Mat;
	XMFLOAT4X4 dispOffset0Mat;
	XMFLOAT4X4 dispOffset1Mat;

	//Store height/width of the grid
	float width;
	float depth;

private:
	//Create buffers and load textures
	void CreateWaveBuffers(ID3D11Device* device);
	void CreateWaveTextures(ID3D11Device* device);
};